package com.winner.data.controller;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.winner.data.entity.bo.ChartBo;
import com.winner.data.entity.dto.ChartDto;
import com.winner.data.entity.vo.ChartValue;
import com.winner.data.exception.R;

/**
 * @Author wangxinle5
 * @since 2025-08-05
 */
@RestController
@RequestMapping("/")
public class ChartController extends BaseController {


    /**
     * 查询折线图
     *
     * @param metricChartDto metricChartDto
     * @return 结果
     */
    @PostMapping("/getMetricChart")
    public R getMetricChart(@RequestBody ChartDto metricChartDto) {
        // 查询数据库list(日期字段+采集值字段)
        List<ChartBo> metricChartBoList = null;
        // 因为数据库采集的时间可能是不连续的, 如果没有则不返回即可. 无需根据日期连续补全
        List<String> dateList = metricChartBoList.stream().map(ChartBo::getDatetime).collect(Collectors.toList());
        List<Double> valueList = metricChartBoList.stream().map(ChartBo::getData).collect(Collectors.toList());
        Map<String, Object> hm = new LinkedHashMap<>();
        // 折线图报表X轴时间
        hm.put("dateList", dateList);
        ArrayList<ChartValue> list = new ArrayList<>();
        list.add(new ChartValue("采集值", valueList));
        hm.put("valueList", list);
        return R.success(hm);
    }
}
